#include "head.h"
#define FILENAME "1.getopt.c"
#define MAX_SIZE 1024 
#define ONE_SIZE 1024

int main() {
    int fd;
    char buff[MAX_SIZE] = {0};
    if ((fd = open(FILENAME, O_RDONLY)) < 0) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    size_t rsize = 0;
    size_t tmpSize = 0;
    while (tmpSize = read(fd, buff, ONE_SIZE)) {
        if (tmpSize < 0) {
            perror("read");
            exit(EXIT_FAILURE);
        }
        rsize += tmpSize;
    }
    printf("file size: %ld\n", rsize);
    FILE* fp = fdopen(fd, "r");
    int len = 0;
    if (fseek(fp, 0, SEEK_END) < 0 || (len = ftell(fp)) == 0 || fseek(fp, 0, SEEK_SET)) {
        perror("fseek");
        exit(1);
    }
    printf("file size 2: %d\n", len);

    return 0;
}